﻿using System;
using System.Collections.Generic;
using System.Text;
using DotNetX;

namespace DotNetX.StringTokenization
{
    /// <summary>
    /// The date time parameter
    /// </summary>
    public class DateTimeParameter : StringTokenizationParameter
    {
        public DateTimeParameter()
            : base("datetime", string.Empty)
        {
        }

        /// <summary>
        /// The key of this parameter
        /// </summary>
        public override string Key
        {
            get
            {
                // return the key
                return "datetime";
            }
            set
            {
                // don't set
                return;
            }
        }

        /// <summary>
        /// The value of this parameter
        /// </summary>
        public override object Value
        {
            get
            {
                // the date in question
                DateTime date = DateTime.Now;

                // are we to return a utc, local or formatted/default date?
                if (this.Modifier.ToLower() == "local")
                    return date.ToLocalTime();
                else if (this.Modifier.ToLower() == "utc")
                    return date.ToUniversalTime();
                else
                    return date.ToString(this._modifierValue);
            }
            set
            {
                // don't set
                return;
            }
        }

        /// <summary>
        /// The preset modifiers for this parameter
        /// </summary>
        public override Dictionary<string, string> ModifierNames
        {
            get
            {
                // return the names
                return GetModifierNames();
            }
        }

        /// <summary>
        /// This returns the per-set modifier names
        /// </summary>
        /// <returns></returns>
        private static Dictionary<string, string> GetModifierNames()
        {
            // create the collection
            Dictionary<string, string> names = new Dictionary<string, string>();

            // add the values
            names.Add("shortdate", "dd/MM/yyyy");
            names.Add("longdate", "dd MMMMM yyyy");
            names.Add("shorttime", "HH:mm");
            names.Add("longtime", "HH:mm:ss");

            // these values will be trapped and the appropriate DateTime method called
            names.Add("utc", "utc");
            names.Add("local", "local");

            // return the names
            return names;
        }

        /// <summary>
        /// This returns the sample parameters using all avaliable modifier names for this parameter
        /// </summary>
        /// <returns></returns>
        public override List<StringTokenizationParameter> GetSampleParametersWithModifierNames()
        {
            // create the collection
            List<StringTokenizationParameter> parameters = new List<StringTokenizationParameter>();

            // create the sample parameters
            foreach (KeyValuePair<string, string> modifier in ModifierNames)
            {
                // create the parameter
                StringTokenizationParameter p = new DateTimeParameter();

                // set the modifier
                p.Modifier = modifier.Key;

                // add the parameter
                parameters.Add(p);
            }

            // return the samples
            return parameters;
        }
    }
}